<?php
	include("includes/connect.php");
	include("includes/function.php");

	$payfor_id				= $_POST["h_key"];
	$gov						= $_POST["gov"];
	$gang					= $_POST["gang"];
	$dd_budget_year	= $_POST["dd_budget_year"];
	$p_id			= $_POST["p_id"];
	$treasury_id			= $_POST["treasury_id"];
	$treasury_date			= $_POST["treasury_date"];
	$panngan2_name	= $_POST["panngan2_name"];
	$panngan3_name	= $_POST["panngan3_name"];
	$acc_id			= $_POST["acc_id"];
	$elass			= $_POST["elass"];
	$dd_expend_type			= $_POST["dd_expend_type"];
	$dd_expend_sub_type			= $_POST["dd_expend_sub_type"];
	$dd_expend_mini_type			= $_POST["dd_expend_mini_type"];
	$inpValues			= $_POST["inpValues"];
	$inpTax			= $_POST["inpTax"];
	$inpTotal			= $_POST["inpTotal"];
	$WithholdingTax			= $_POST["WithholdingTax"];
	$inpPenalty			= $_POST["inpPenalty"];
	$inpNet			= $_POST["inpNet"];
	$ppID			= $_POST["ppID"];

	$company_name			= $_POST["company_name"];
	$task						= $_POST["task"];
	$petition_id			= $_POST["petition_id"];

	//echo $payfor_id, $ppID;

	if ($task == "edit") {

		$sql ="UPDATE tbl_petition SET dd_expend_type = '$dd_expend_type', dd_expend_sub_type = '$dd_expend_sub_type', dd_expend_mini_type = '$dd_expend_mini_type', inpValues = '$inpValues', inpTax = '$inpTax', inpTotal = '$inpTotal', WithholdingTax = '$WithholdingTax', inpPenalty ='$inpPenalty', inpNet = '$inpNet' WHERE petition_id = '$petition_id'";

		//echo $sql;
		$db = new myDBS;
		$db->runSQL($sql);
		echo $petition_id;
	} else {
		$sql ="INSERT INTO tbl_petition(ppID, gov, gang, dd_budget_year, p_id, treasury_id, treasury_date, panngan2_name, panngan3_name, acc_id, elass, dd_expend_type, dd_expend_sub_type, dd_expend_mini_type, inpValues, inpTax, inpTotal, WithholdingTax, inpPenalty, inpNet, payfor_id, company_name) VALUES('$ppID', '$gov', '$gang', '$dd_budget_year', '$p_id', '$treasury_id', '$treasury_date', '$panngan2_name', '$panngan3_name', '$acc_id', '$elass', '$dd_expend_type', '$dd_expend_sub_type', '$dd_expend_mini_type', '$inpValues', '$inpTax', '$inpTotal', '$WithholdingTax', '$inpPenalty', '$inpNet', '$payfor_id', '$company_name')";

		//echo $sql;
		$db = new myDBS;
		$last_id = $db->insData($sql);
		
		$sql = "UPDATE pp_check_job SET status = 1 WHERE ppID = '$ppID'";
		$db->runSQL($sql);

		echo $last_id;
	}

	//echo $sql;
	/*
	$db = new myDBS;
	$last_id = $db->insData($sql);
	echo $last_id;

	$where = "xxx_id = '$payfor_id' and creditor_name IS NOT NULL";
	//echo $where;
	$result = $db->showData1("temp_creditor", $where);

	while ( $rows = $db->fetch_object ( $result )){
		$sql = "INSERT INTO tbl_payfor(payfor_id, creditor_name, amount) VALUES('$payfor_id', '". $rows->creditor_name ."', '" . $rows->amount ."')";
		//echo $sql;
		$db->insData($sql);
	}
	*/
/*
	if (isset ($name)) {
		mysql_query("INSERT INTO tblProfile(name, email, tel, birthdate) VALUES ('$name', '$email', '$tel', '$datepicker')") or die(mysql_error($connect));
		echo "seccess";
	} else {
		//mysql_error($connect);
		echo "Error from filename:addProfile.php";
	}
*/
?>
